package com.nahan.secondapplication.CityList;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.nahan.secondapplication.CityList.bean.CityBean;
import com.nahan.secondapplication.CityList.bean.DistrictBean;
import com.nahan.secondapplication.CityList.bean.ProvinceBean;
import com.nahan.secondapplication.R;

/**
 * @describe: 描述：
 * @time: 2020-9-3 17:57:23
 */
public class CityPickerActivity extends AppCompatActivity {
    private TextView dianjie,resultV;
    JDCityPicker cityPicker;
    private JDCityConfig jdCityConfig = new JDCityConfig.Builder().build();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_city_picker);

        dianjie = (TextView) findViewById(R.id.dianjie);
        resultV = (TextView) findViewById(R.id.result_tv);




        jdCityConfig.setShowType(JDCityConfig.ShowType.PRO_CITY_DIS);
        cityPicker = new JDCityPicker();
        //初始化数据
        cityPicker.init(this);
        //设置JD选择器样式位只显示省份和城市两级
        cityPicker.setConfig(jdCityConfig);
        cityPicker.setOnCityItemClickListener(new OnCityItemClickListener() {
            @Override
            public void onSelected(ProvinceBean province, CityBean city, DistrictBean district) {

                String proData = null;
                if (province != null) {
                    proData = "name:  " + province.getName() + "   id:  " + province.getId();
                }

                String cituData = null;
                if (city != null) {
                    cituData = "name:  " + city.getName() + "   id:  " + city.getId();
                }


                String districtData = null;
                if (district != null) {
                    districtData = "name:  " + district.getName() + "   id:  " + district.getId();
                }


//                if (mWheelType == JDCityConfig.ShowType.PRO_CITY_DIS) {
                    resultV.setText("城市选择结果：\n" + proData + "\n"
                            + cituData + "\n"
                            + districtData);
//                } else {
//                    resultV.setText("城市选择结果：\n" + proData + "\n"
//                            + cituData + "\n"
//                    );
//                }
            }

            @Override
            public void onCancel() {
            }
        });
        dianjie.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                cityPicker.showCityPicker();
            }
        });
    }
}
